# -*- coding: iso-8859-2 -*-

import re

from authorshipanalyzer.textmodifier import Editor
from authorshipanalyzer.message import Message

class OtherMessageFilter(Editor):
    '''
    Class removing parts of the message which were not
    written by the author but where forwarded or
    attached.
    '''
    
    def editMessage(self, message):
        ok = []
        for line in message.getText().split('\n'): 
            line     
            if re.match(".+(Original|Forwarded) Message.+", line, re.I) or \
                re.match(".+wiadomo.+(oryginalna|przekazana).+", line, re.I):
                message.setText("\n".join(ok))
                break
            ok.append(line)
                
                
    def __str__(self):
        return __name__
    
if __name__ == "__main__":
    m = Message()
    m.setText("""zainstalujcie sobie gg....\n
  ----- Original Message -----=20\n
  From: Mateusz Winiarski=20\n
  To: info1@mail.agh.edu.pl=20\n
  Sent: Friday, March 21, 2008 10:45 PM\n
  Subject: [info1] Re: Bezw=C5=82adno=C\n
===================================>>>>>>>>>""")
    
    f = OtherMessageFilter()
    f.editMessage(m)
    print m.getText()